param(
	[Parameter(Mandatory=$False)]
	[object]$vdi_list,						            # the vdi list
	[string]$stop_name,                                # the process/service name to be killed
    [ValidateSet("service", "process")]                 # stop type
	[string]$stop_type='process'
)
Switch -regex ($stop_type){
    'process'{
        $stop_action={
            param($line,$cnt,$process_name)
            try{$vdi,$domain,$fid,$env=$line.split(",").trim().ToUpper()}catch{}
            If(New-ScheduledTask $vdi StopProcess -task_arg "-Executionpolicy unrestricted -command `"&{ps|?{`$_.Name -imatch [regex]::new($process_name)}|kill -force}`""){
                SCHTASKS /RUN /S $vdi /tn StopProcess
                Do{
                     If( (SCHTASKS /QUERY /S $vdi /TN StopProcess 2>$null) -imatch "Ready" ){
                        SCHTASKS /DELETE /S $vdi /TN StopProcess /F 1>$null 2>&1
                        break
                    }else{sleep 1}
                }While( $true )
            }
        }
    }
    'service'{
        $stop_action={
            param($line,$cnt,$service_name)
            try{$vdi,$domain,$fid,$env=$line.split(",").trim().ToUpper()}catch{}
            get-service -cn $vdi|?{$_.Name -imatch ([regex]::new($process_name))|%{stop-service -Force -ea 0}}
        }
    }
}
Start-BulkThreads $vdi_list.split("`n") $stop_action ([string]::Join("|", ($check_name.split("`n").trim()|?{![string]::IsNullOrWhiteSpace($_)})))